package net.huashitong.Project.web;

import jodd.util.StringUtil;
import net.huashitong.Project.entity.NewProjects;
import net.huashitong.Project.service.EarlyWarningService;
import net.huashitong.Project.service.NewProjectsService;
import net.huashitong.Project.service.NodeProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping(value = "/test1")
public class Test1Controller {
    @Autowired
    private NewProjectsService newProjectsService;
    @Autowired
    private NodeProcessService nodeProcessService;
    @Autowired
    private EarlyWarningService earlyWarningService;

    @ResponseBody
    @RequestMapping(value = "/updateEachProcess/{projectId}", method = RequestMethod.GET)
    public String updateBatchProcess(@PathVariable String projectId){
        List<String> sysIds = new ArrayList<>();
        sysIds.add(projectId);
        newProjectsService.updateNodeProcess(sysIds);
        return "单个项目流程更新成功";
    }

    @ResponseBody
    @RequestMapping(value = "/updateProjectsProcess", method = RequestMethod.GET)
    public String updateBatchProcess(){
        List<String> sysIds = new ArrayList<>();
        List<NewProjects> projects = newProjectsService.query();
        for (NewProjects project : projects) {
            sysIds.add(project.getSysId());
        }
        newProjectsService.updateNodeProcess(sysIds);
        return "所有项目流程更新成功";
    }

    @ResponseBody
    @RequestMapping(value = "/getNodeProcessDate/{projectId}", method = RequestMethod.GET)
    public String getNodeProcessDate(@PathVariable String projectId) throws ParseException {
        List<String> projects = new ArrayList<>();
        projects.add(projectId);
        nodeProcessService.updateNodeProcessDate(projects);
        return "单个项目计划时间更新成功";
    }

    @ResponseBody
    @RequestMapping(value = "/getAllProjectsNodeProcessDate", method = RequestMethod.GET)
    public String getAllProjectsNodeProcessDate() throws ParseException {
        List<NewProjects> projects = newProjectsService.query();
        List<String> projectIdList = new ArrayList<>();
        for (NewProjects project : projects) {
//            if(StringUtil.isNotBlank(project.getCreateDate())){
                projectIdList.add(project.getSysId());
//            }
        }
        nodeProcessService.updateNodeProcessDate(projectIdList);
        return "所有新的项目项目计划时间更新成功";
    }

    /**
     * 进行中的节点通知
     * @return
     * @throws ParseException
     */
    @ResponseBody
    @RequestMapping(value = "/beginNode", method = RequestMethod.GET)
    public String beginNode() throws ParseException {
        earlyWarningService.updateNode();
        return "进行中的节点通知";
    }

}
